package com.woniuxy.main.handler;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.shiro.session.Session;
import org.apache.shiro.web.session.HttpServletSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.main.pojo.Student;
import com.woniuxy.main.pojo.User;

import com.woniuxy.main.service.UserStudentService;
import com.woniuxy.main.util.SessionUtil;

@Controller
@RequestMapping("/UserStudent")
@Scope("prototype")
public class UserStudentHandler {
	@Resource
	private UserStudentService userStudentService;

	public UserStudentService getUserStudentService() {
		return userStudentService;
	}

	public void setUserStudentService(UserStudentService userStudentService) {
		this.userStudentService = userStudentService;
	}

	@RequestMapping("/addStuInfo")
	@ResponseBody
	public String addStuInfo(HttpServletRequest request, User user, Student student) {
		Session session = SessionUtil.getSession();
		int uid = (int) session.getAttribute("uid");
		// 模拟将session中的uid放入这个对象
		user.setUid(uid);
		student.setUid(uid);

		// 将需要更新的字段写入数据库,返回总共影响行数
		int row = userStudentService.addStuInfo(user, student);

		if (row != 0) {

			HttpSession session1 =request.getSession();
			session1.setAttribute("address", user.getAddress());
			session.setAttribute("address", user.getAddress());

			return "信息修改成功";
		}

		return "信息修改失败";

	}

}
